//
//  tzxc.m
//  PASystem
//
//  Created by michael on 16/8/24.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "tzxc.h"

@implementation tzxc

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
    UIColor *myColor = [UIColor colorWithWhite:0.8 alpha:0.3];
self.backgroundColor = myColor;

          }
    return self;
}
- (void)setId:(NSString *)id{

    

//NSLog(@"11%@",id);
_id = id;
 [self initview];
[self request];
 
}
- (void)initview{
_tableview = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
_tableview.frame = CGRectMake(10,10, KScreenWidth-20, KScreenHeight-64-46-80-20);
_tableview.backgroundColor = [UIColor whiteColor];
_tableview.dataSource = self;
_tableview.delegate = self;
self.tableview.bounces = NO;
[self addSubview:_tableview];

}
- (void)request{
NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
  //1
 NSString *json =[NSString stringWithFormat: @"{'action':tdfzMch,'service':DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,_id];
     NSArray * array = @[@{@"arg0":json}];
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
    
     NSDictionary *dic = JSON[@"reason"];
        NSDictionary *dict = dic[@"attrs"];
       _dic = dict;
    
 [self.tableview reloadData];
    }
     failure:^(NSError *error) {
        

    }];

//1
 NSString *json1 =[NSString stringWithFormat: @"{'action':xcapMch,'service':DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,_id];
     NSArray * array1 = @[@{@"arg0":json1}];
    [HttpTools requestWithURL:BaseURL arrays:array1 method:Basemethod success:^(id JSON) {
    
     NSDictionary *dic = JSON[@"reason"];
        NSDictionary *dict = dic[@"attrs"];
       _dic1 = dict;
    //SITUATION
 [self.tableview reloadData];
    }
     failure:^(NSError *error) {
        

    }];

NSString *json2 =[NSString stringWithFormat: @"{'action':cpxzMch,'service':DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,_id];
     NSArray * array2 = @[@{@"arg0":json2}];
    [HttpTools requestWithURL:BaseURL arrays:array2 method:Basemethod success:^(id JSON) {
    
     NSDictionary *dic = JSON[@"reason"];
        NSDictionary *dict = dic[@"attrs"];
       _dic2 = dict;
    //SITUATION
 [self.tableview reloadData];
    }
     failure:^(NSError *error) {
        

    }];
NSString *json3 =[NSString stringWithFormat: @"{'action':tdjlMch,'service':DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,_id];
     NSArray * array3 = @[@{@"arg0":json3}];
    [HttpTools requestWithURL:BaseURL arrays:array3 method:Basemethod success:^(id JSON) {
    
     NSDictionary *dic = JSON[@"reason"];
        NSDictionary *dict = dic[@"attrs"];
       _dic3 = dict;
    //SITUATION
 [self.tableview reloadData];
    }
     failure:^(NSError *error) {
        

    }];
NSString *json4 =[NSString stringWithFormat: @"{'action':csjsMch,'service':DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,_id];
     NSArray * array4 = @[@{@"arg0":json4}];
    [HttpTools requestWithURL:BaseURL arrays:array4 method:Basemethod success:^(id JSON) {
    
     NSDictionary *dic = JSON[@"reason"];
        NSDictionary *dict = dic[@"attrs"];
       _dic4 = dict;
    //SITUATION
 [self.tableview reloadData];
    }
     failure:^(NSError *error) {
        

    }];





}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat H = 44;
if (indexPath.row == 6||indexPath.row ==5||indexPath.row ==4||indexPath.row ==3){

return 80;
}
 
else{

return H;
}

}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==0) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
     cell.selectionStyle = UITableViewCellSelectionStyleNone;
      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, cell.contentView.height)];
    label.text = @"日期:";
           //时间
  NSString *string = _dic[@"DATETIME"];
  NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
    fmt.dateFormat = @"MMM d, yyyy HH:mm:ss aa";
 fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en-US"];
     NSDate *date = [fmt dateFromString:string];
     NSDateFormatter *fm = [[NSDateFormatter alloc] init];
    fm.dateFormat = @"yyyy-MM-dd";
     NSString *selfYear = [fm stringFromDate:date];


    
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100, label.height)];
 label2.textAlignment = NSTextAlignmentRight;
    label2.text = selfYear;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
if (indexPath.row==1) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, cell.contentView.height)];
    label.text = @"城市:";
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100, label.height)];
 
 
//     label2.text = _dic[@"cause"];
label2.textAlignment = NSTextAlignmentRight;
    label2.text = [NSString stringWithFormat:@"%@",_dic[@"CITY"]];
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
if (indexPath.row==2) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, cell.contentView.height)];
    label.text = @"行程:";
    
      label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
 UILabel *label2= [[UILabel alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100, label.height)];
    label2.text = _dic[@"ROUNTING"];
    label2.textAlignment = NSTextAlignmentRight;
     label2.font = [UIFont systemFontOfSize:12];
    [cell.contentView addSubview:label2];
    return cell;
 
 }
if (indexPath.row==3) {
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, cell.contentView.height)];
    label.text = @"行程安排:";
    label.textColor = [UIColor blueColor];
    
 
     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];
   NSString *string = _dic1[@"SITUATION"];
NSString *result = [string stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];

result = [result stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
result = [result stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];


 UIWebView *web= [[UIWebView alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100,80)];
 web.delegate = self;
 [web loadHTMLString:result baseURL:nil];
 web.backgroundColor = [UIColor whiteColor];
       [cell.contentView addSubview:web];
    return cell;
 
 }
if (indexPath.row==4){
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, cell.contentView.height)];
    label.text = @"出行须知:";
    label.textColor = [UIColor blueColor];

     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];

    

   NSString *string = _dic2[@"SITUATION"];
NSString *result = [string stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];

result = [result stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
result = [result stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];


 UIWebView *web= [[UIWebView alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100,80)];
 web.delegate = self;
 [web loadHTMLString:result baseURL:nil];
 web.backgroundColor = [UIColor whiteColor];
       [cell.contentView addSubview:web];    return cell;
 
 }
 
 if (indexPath.row==5){
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, cell.contentView.height)];
    label.text = @"表图纪律:";
    label.textColor = [UIColor blueColor];

     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];

     NSString *string = _dic3[@"SITUATION"];
NSString *result = [string stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];

result = [result stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
result = [result stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];


 UIWebView *web= [[UIWebView alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100,80)];
 web.delegate = self;
  web.backgroundColor = [UIColor whiteColor];

 [web loadHTMLString:result baseURL:nil];
       [cell.contentView addSubview:web];
    return cell;
 
 }
 else{
 
     UITableViewCell* cell = [[UITableViewCell alloc]init];
          cell.selectionStyle = UITableViewCellSelectionStyleNone;

      UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, cell.contentView.height)];
    label.text = @"城市介绍:";
    label.textColor = [UIColor blueColor];

     label.font = [UIFont systemFontOfSize:14];
    [cell.contentView addSubview:label];

    

   NSString *string = _dic4[@"SITUATION"];
NSString *result = [string stringByReplacingOccurrencesOfString:@"&quot;" withString:@"\""];

result = [result stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
result = [result stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];


 UIWebView *web= [[UIWebView alloc]initWithFrame:CGRectMake(label.right, label.top, KScreenWidth-20-100,80)];
 web.delegate = self;
 [web loadHTMLString:result baseURL:nil];
 web.backgroundColor = [UIColor whiteColor];
       [cell.contentView addSubview:web];
    return cell;

 
 }

  
 
 }
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 7;
}

@end

